gadgets.window.adjustHeight(50);

var $API_HOST = 'http://localhost.com:8000/api';

try {

    matches = google.contentmatch.getContentMatches();
    console.log(matches);
    var messageID =  matches[4]['id'];
    var data = {
        subject: matches[0]['subject'],
        body: matches[1]['body'],
        from: matches[2]['from'],
        to: matches[3]['to'],
        id: messageID
    };

    if (matches.length > 5) {
        data.cc = matches[5]['cc'];
    }


    $("#btn-send-ajax").click(function () {
        try {
            $.ajax({
                type: "POST",
                url: $API_HOST + "/entries/add",
                data: JSON.stringify(data),
                success: function (result) {
                    //alert(result);
                },
                dataType: "json"
            });
        } catch (err) {
            console.log(err);
        }
    });

    $("#btn-send-ajax").click(function () {
        try {
            $.ajax({
                type: "GET",
                url: $API_HOST + "/entry/?sku=" + messageID,
                success: function (result) {
                    alert(result);
                }
            });
        } catch (err) {
            console.log(err);
        }
    });

} catch (err) {
    console.log(err);
}